﻿using AutoMapper;
using Microsoft.Extensions.Logging;
using NetCore.Common.Helper;
using NetCore.IRepository;
using NetCore.IRepository.User;
using NetCore.IServices.User;
using NetCore.Model.Enity;
using NetCore.Model.VeiwModels;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace NetCore.Service.User
{
    public class Order_LayerwinDingmachineEquipmentService : BaseService<SysUser>, IUserService
    {
        private readonly IUserRepository userDal;
        private readonly IMapper iMapper;

        //private readonly IMain_RedisCacheManager redisCacheManager;
        private readonly ILogger<Order_LayerwinDingmachineEquipmentService> logger;

        public Order_LayerwinDingmachineEquipmentService(IBaseRepository<SysUser> baseRepository, IUserRepository userRepository, IMapper IMapper, ILogger<Order_LayerwinDingmachineEquipmentService> Logger) : base(baseRepository)//IMain_RedisCacheManager RedisCacheManager,
        {
            userDal = userRepository;
            iMapper = IMapper;
            //redisCacheManager = RedisCacheManager;
            logger = Logger;
        }

        public async Task<int> GetCount()
        {
            return await userDal.GetCount();
        }

        /// <summary>
        /// 获取用户详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        //[Caching(AbsoluteExpiration = 1)]
        public async Task<UserViewModel> GetUserDetails(int id)
        {
            SysUser userinfo = await userDal.QueryByID(id);

            if (userinfo != null)
            {
                //名称相同进行映射
                iMapper.Map<UserViewModel>(userinfo);
                UserViewModel model = iMapper.Map<UserViewModel>(userinfo);
                model.Address = "北京市xx区xx小区";
                //复杂深拷贝映射
                logger.LogError("错误日志");
                return model;
            }
            else
            {
                return null;
            }
        }

        public async Task<string> AddEquipmentInfo(SysEquipmentinfo sysEquipmentinfo)
        {
            long id = await userDal.AddEquipmentInfo(sysEquipmentinfo);
            return JsonReturnHelper.Success("添加设备信息成功", id);
        }

        public List<OrderLayerwindingmachineequipment> GetOrder_LayerwindingmachineEquipmentInfo()
        {
            List<OrderLayerwindingmachineequipment> orderLayerwindingmachineequipments = userDal.GetOrder_LayerwindingmachineEquipmentInfo();

            return orderLayerwindingmachineequipments;
        }
    }
}